﻿package lobby
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import lobby.exchangeddata.BetStatusInfo;
	import lobby.events.LobbyEvent;
	import lobby.exchangeddata.BetStatusItemInfo;
	import lobby.exchangeddata.HashTable;
	
	/**
	 * ...
	 * @author Tom
	 */
	public class BetStatusPanel extends MovieClip
	{
		public var txtPastTf:TextField;
		public var txtOkTf:TextField
		public var txtBetRecTf:TextField;
		public var txtDateTf:TextField;
		public var txtTimeTf:TextField;
		public var txtTableTf:TextField;
		public var txtGameSetTf:TextField;
		public var txtBetCodeTf:TextField;
		public var txtResultTf:TextField;
		public var txtAmountTf:TextField;
		public var txtWinTf:TextField;
		public var txtCommissionAmountTf:TextField;
		public var txtReportMessageTf:TextField;
		
		public var btnCloseReport:SimpleButton;
		public var statusMc:MovieClip;
		public var statusBoard:Sprite = new Sprite();
		public var pageControl:PageControl;
		
		public function BetStatusPanel()
		{
			hide();
			txtReportMessageTf.visible = false;
			this.txtOkTf.mouseEnabled = false;
			this.btnCloseReport.addEventListener(MouseEvent.CLICK, closeHdl);
			this.statusMc.addChild(statusBoard);
		}
		
		private function closeHdl(e:Event):void
		{
			hide();
		}
		
		public function initText(hashTableInfo:HashTable):void
		{
			this.txtPastTf.text = hashTableInfo.lookupString("presultMsg");
			this.txtOkTf.text = hashTableInfo.lookupString("btnOK");
			this.txtBetRecTf.text = hashTableInfo.lookupString("betNoMsg");
			this.txtDateTf.text = hashTableInfo.lookupString("DateMsg");
			this.txtTimeTf.text = hashTableInfo.lookupString("TimeMsg");
			this.txtTableTf.text = hashTableInfo.lookupString("tblMsg");
			this.txtGameSetTf.text = hashTableInfo.lookupString("gameMsg");
			this.txtBetCodeTf.text = hashTableInfo.lookupString("betMsg");
			this.txtResultTf.text = hashTableInfo.lookupString("resultMsg");
			this.txtAmountTf.text = hashTableInfo.lookupString("amountMsg");
			this.txtWinTf.text = hashTableInfo.lookupString("winMsg");
			this.txtCommissionAmountTf.text = hashTableInfo.lookupString("CommissionAmount");
		}
		
		public function updateValueBetStatus(info:Object):void
		{
			var betStatus:BetStatusInfo = BetStatusInfo(info);
			removeStatus();
			for (var i:int = 0; i < betStatus.statusData.length; i++)
			{				
				var itemData:BetStatusItemInfo = betStatus.statusData[i];
				var itemMc:BetStatusItem = new BetStatusItem(itemData);
				itemMc.x = 0;
				itemMc.y = i * 25.75;
				statusBoard.addChild(itemMc);
			}
			if (betStatus.pageNum > 1 && this.visible == false)
			{
				this.pageControl.addPageToPageList(this.pageControl.pageList, betStatus.pageNum, "");
				this.pageControl.visible = true;
			}
		}
		
		public function show():void
		{
			this.visible = true;
		}
		
		public function hide():void
		{
			this.visible = false;
			this.pageControl.visible = false;
		}
		
		private function removeStatus():void
		{			
			var numberChid:int = statusBoard.numChildren;
			if (numberChid > 0)
			{
				for (var j:int = 0; j < numberChid; j++)
				{
					var status:DisplayObject = statusBoard.removeChildAt(0);
					status = null;
				}
			}
		}
	}

}